//
//  BrokerCellView.m
//  WGFGlobalHouses
//
//  Created by welldone on 15/5/21.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "BrokerCellView.h"
#import "config.h"
#import "UIImageView+WebCache.h"
#import "UIView+circular.h"
#import "StringTool.h"
#import "API.h"

//#define imgForward @"http://files.wgfcdn.com/"

@interface BrokerCellView ()

@property (weak, nonatomic) IBOutlet UIButton *selecteStatuBtn;
@property (weak, nonatomic) IBOutlet UIImageView *headImg;

@property (weak, nonatomic) IBOutlet UILabel *nameLab;
@property (weak, nonatomic) IBOutlet UILabel *companyLab;
@property (weak, nonatomic) IBOutlet UILabel *mobileLab;

@property (weak, nonatomic) IBOutlet UILabel *tipLab;

@property (weak, nonatomic) IBOutlet UIView *rightView;



@property (nonatomic,strong) NSLayoutConstraint* conLay;

@end

@implementation BrokerCellView


+(instancetype)creatView{

    
    BrokerCellView *view = [[[NSBundle mainBundle]loadNibNamed:@"BrokerCellView" owner:nil options:nil]lastObject];
    view.tipLab.hidden = YES;
    
    for (NSLayoutConstraint *conLayout in view.constraints) {
        
        if (conLayout.firstItem==view.headImg&&conLayout.firstAttribute ==NSLayoutAttributeLeading) {
            view.conLay = conLayout;
            break;
        }
    }
    
    [view.headImg imgViewToCircular:view.headImg];
    return view;
}


-(void)setData:(BorkerCellModel *)data
{
    
    if([StringTool isBlankString:data.brokerAvatar])
    {
        [self.headImg sd_setImageWithURL:nil placeholderImage:[UIImage imageNamed:@"user_portiart"]];
    }else{
        
        NSURL *url = [NSURL URLWithString: [API videoUrlMake:data.brokerAvatar]
];
        [self.headImg sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"user_portiart"]];
    }
    
    self.nameLab.text = data.brokerName;
    self.companyLab.text = data.storeName;
    self.mobileLab.text = data.brokerMobile;
    self.tipLab.hidden = data.status == 0? YES:NO;
    self.tipLab.text = data.status == 0?@"":@"已禁用";
    
    [self.selecteStatuBtn setHighlighted:data.isSelected];
}

-(void)setIsEditMode:(Boolean)isEditMode{
    
    [self.rightView setHidden:isEditMode];
    
     self.conLay.constant = isEditMode?40:8;
    
    [self layoutIfNeeded];
}

-(void)beQueryStyleCell{

    
    self.tipLab.hidden = YES;
    
    [self.rightView setHidden:true];
    
    self.conLay.constant = 8;
    
    [self layoutIfNeeded];
}


@end
